import {BasicColumn} from '/@/components/Table';
import {FormSchema} from '/@/components/Table';
import { rules} from '/@/utils/helper/validator';
import { render } from '/@/utils/common/renderUtils';
import {JVxeTypes,JVxeColumn} from '/@/components/jeecg/JVxeTable/types'
//列表数据
export const columns: BasicColumn[] = [
   {
    title: '线路名称',
    align:"center",
    dataIndex: 'routesId_dictText'
   },
   {
    title: '站点名称',
    align:"center",
    dataIndex: 'siteName'
   },
  //  {
  //   title: '站点经度',
  //   align:"center",
  //   dataIndex: 'siteLongitude'
  //  },
  //  {
  //   title: '站点纬度',
  //   align:"center",
  //   dataIndex: 'siteLatitude'
  //  },
   {
    title: '站点排序',
    align:"center",
    dataIndex: 'siteSort'
   },
   {
    title: '站点状态',
    align:"center",
    dataIndex: 'siteStatus_dictText'
   },
   {
    title: '学生数',
    align:"center",
    dataIndex: 'studentNum'
   },
];
//查询数据
export const searchFormSchema: FormSchema[] = [
  {
    label: "线路名称",
    field: 'routesId',
    component: 'JDictSelectTag',
    componentProps:{
      dictCode:"school_bus_routes,routes_name,id"
   },
   dynamicRules: ({model,schema}) => {
    return [
           //{message: '请选择线路!'},
    ];
  }
    //colProps: {span: 6},
 },
	{
      label: "站点名称",
      field: "siteName",
      component: 'JInput',
      //colProps: {span: 6},
 	},
	{
      label: "站点状态",
      field: "siteStatus",
      component: 'JDictSelectTag',
      componentProps:{
          dictCode:"school_bus_site_status"
      },
      //colProps: {span: 6},
 	},
   {
      label: "学生姓名",
      field: "studentName",
      component: 'Input', 
      //colProps: {span: 6},
	},
  {
    label: "学生学号",
    field: "studentCode",
    component: 'Input', 
    //colProps: {span: 6},
},
];
//表单数据
export const formSchema: FormSchema[] = [
  {
    label: '线路',
    field: 'routesId',
    component: 'JDictSelectTag',
    componentProps:{
        dictCode:"school_bus_routes,routes_name,id"
     },
     dynamicRules: ({}) => {
      return [
             { required: true, message: '请选择线路!'},
      ];
 },
  },
  {
    label: '站点名称',
    field: 'siteName',
    component: 'Input',
    dynamicRules: ({}) => {
          return [
                 { required: true, message: '请输入站点名称!'},
          ];
     },
  },
  // {
  //   label: '站点经度',
  //   field: 'siteLongitude',
  //   component: 'Input',
  // },
  // {
  //   label: '站点纬度',
  //   field: 'siteLatitude',
  //   component: 'Input',
  // },
  {
    label: '站点排序',
    field: 'siteSort',
    defaultValue: 1,
    component: 'InputNumber',
    dynamicRules: ({}) => {
          return [
                 { required: true, message: '请输入站点排序!'},
                 { pattern: /^-?\d+\.?\d*$/, message: '请输入数字!'},
          ];
     },
  },
  {
    label: '站点状态',
    field: 'siteStatus',
    defaultValue: "1",
    component: 'JDictSelectTag',
    componentProps:{
        dictCode:"school_bus_site_status"
     },
  },
	// TODO 主键隐藏字段，目前写死为ID
	{
	  label: '',
	  field: 'id',
	  component: 'Input',
	  show: false
	},
];
//子表单数据
//子表表格配置
export const schoolBusSiteToStudentColumns: JVxeColumn[] = [
    {
      title: '学生',
      key: 'studentName',
      type: JVxeTypes.popup,
      popupCode:"select_site_person",
      fieldConfig: [
        { source: 'id', target: 'studentId' },
        { source: 'name', target: 'studentName' },
      ],

      width:"200px",
      placeholder: '请输入${title}',
      defaultValue:'',
    },
    {
      title: '乘坐类型',
      key: 'rideType',
      type: JVxeTypes.select,
      options:[],
      dictCode:"school_bus_site_ride_type",
      width:"200px",
      placeholder: '请输入${title}',
      defaultValue:"1",
        validateRules: [
          { required: true, message: '${title}不能为空' },
        ],
    },
  ]


// 高级查询数据
export const superQuerySchema = {
  routesId: {title: '校车线路',order: 0,view: 'list', type: 'string',dictTable: 'school_bus_routes', dictCode: 'id', dictText: 'routes_name',},
  siteName: {title: '站点名称',order: 1,view: 'text', type: 'string',},
  siteStatus: {title: '站点状态',order: 5,view: 'list', type: 'string',dictCode: 'school_bus_site_status',},
  //子表高级查询
  schoolBusSiteToStudent: {
    title: '站点学生',
    view: 'table',
    fields: {
        siteId: {title: '站点',order: 0,view: 'text', type: 'string',},
        studentName: {title: '学生名称',order: 2,view: 'popup', type: 'string',code: 'select_site_person', orgFields: 'name', destFields: 'studentName', popupMulti: false,},
        rideType: {title: '乘坐类型',order: 2,view: 'list', type: 'string',dictCode: 'school_bus_site_ride_type',},
    }
  },
};

/**
* 流程表单调用这个方法获取formSchema
* @param param
*/
export function getBpmFormSchema(_formData): FormSchema[]{
// 默认和原始表单保持一致 如果流程中配置了权限数据，这里需要单独处理formSchema
  return formSchema;
}

//列表数据
export const studentColumns: BasicColumn[] = [
  {
   title: '学生姓名',
   align:"center",
   dataIndex: 'name'
  },
  {
   title: '学生学号',
   align:"center",
   dataIndex: 'code'
  },
  {
    title: '性别',
    align:"center",
    dataIndex: 'sex',
     customRender: ({ text }) => {
       return render.renderDict(text, 'sex');
     },
   },
  {
   title: '班级',
   align:"center",
   dataIndex: 'deptName'
  }
];

//查询数据
export const studentSearchFormSchema: FormSchema[] = [
   {
      label: "学生姓名",
      field: "studentName",
      component: 'Input', 
      //colProps: {span: 6},
	},
  {
    label: "学生学号",
    field: "studentCode",
    component: 'Input', 
    //colProps: {span: 6},
},
];